package com.xique.system.api.factory;

import com.xique.common.core.domain.R;
import com.xique.system.api.RemoteSystemDeptService;
import com.xique.system.api.dto.SystemDeptDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 部门服务降级处理
 *
 * @author WLD
 */
@Component
public class RemoteSystemDeptFallbackFactory implements FallbackFactory<RemoteSystemDeptService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteSystemDeptFallbackFactory.class);

    @Override
    public RemoteSystemDeptService create(Throwable throwable) {
        log.error("系统部门服务调用失败:{}", throwable.getMessage());
        return new RemoteSystemDeptService() {
            @Override
            public R<SystemDeptDTO> getInfoById(Long id) {
                return R.fail("获取系统部门信息失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SystemDeptDTO>> allList() {
                return R.fail("获取所有部门失败:" + throwable.getMessage());
            }
        };
    }

}
